package com.jl.jlapp.mvp.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.ActivityMessageListAdapter;
import com.jl.jlapp.eneity.ActivityMessageByUserIdModel;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;

import org.reactivestreams.Subscription;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.FlowableSubscriber;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ActivityMessageListActivity extends Activity {
    List<ActivityMessageByUserIdModel.ResultDataBean.ActivityMessageListBean> activityMessageList = new ArrayList();
    ActivityMessageListAdapter activityMessageListAdapter;
    @BindView(R.id.activity_message_recycler_view)
    RecyclerView activityMessageRecyclerView;
    @BindView(R.id.no_message_linear)
    LinearLayout noMessageLinear;
    int userId = 0;

    private void getNetData() {
        Net.get().getActivityMessageByUserId(this.userId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).
                subscribe(new CommonObserver<ActivityMessageByUserIdModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(ActivityMessageByUserIdModel activityMessageByUserIdModel) {

                    }
                });
    }

    private void setAdpter() {
        this.activityMessageRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        this.activityMessageListAdapter = new ActivityMessageListAdapter(R.layout.activity_message_list_item_layout, this.activityMessageList);
        this.activityMessageRecyclerView.setAdapter(this.activityMessageListAdapter);
        this.activityMessageListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                paramAnonymousInt = ((ActivityMessageByUserIdModel.ResultDataBean.ActivityMessageListBean) ActivityMessageListActivity.this.activityMessageList.get(paramAnonymousInt)).getActivityInformatId();
                Intent intent = new Intent(ActivityMessageListActivity.this, ActivityNameActivity.class);
                intent.putExtra("activityInformationId", paramAnonymousInt);
                ActivityMessageListActivity.this.startActivity(intent);
            }
        });
    }

    @OnClick({R.id.icon_return})
    public void onClick(View paramView) {
        switch (paramView.getId()) {
            default:
                return;
        }
//    finish();
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_message_list);
        ButterKnife.bind(this);
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        getNetData();
    }
}